<?php
/*class controller for administration login page
 *
 */
class AdminLogin extends Controller {

        //function __construct()
        function AdminLogin()
        {
                parent::Controller();
        }

        function index()
        {
            //create data array
                $data = array();
                //if adminlogin credentials validate, log admin in.
                if (isset($_POST['login']))
                {
                        //Validate and Prep the form
                        $this->load->library('form_validation');
                        $this->form_validation->set_rules('login', 'admin login name', 'required|trim|strtolower');
                        $this->form_validation->set_rules('pass', 'admin password', 'required|trim');

                        $result = $this->form_validation->run();

                        if ($result === TRUE)
                        {
                                //Check the username and password against the database
                                $this->load->model('AdminLogin');
                                $result = $this->AdminLogin->check_credentials($_POST['admin_login'], $_POST['admin_pass']);

                                //If the credentials match against the database, then add a variable to the session cookie
                                if ($result === TRUE)
                                {
                                        $this->session->set_userdata(array('is_logged_in' => TRUE));
                                        header("Location: about/secure");
                                }
                                else
                                //else show these error messages.
                                        $data['error_msg'] = "The username or password was incorrect!";
                        }
                        else
                                $data['error_msg'] = "There was a problem with your submission!";
                }
                   //load adminlogin view
                $this->load->view('AdminLogin', $data);
        }
}
?>